<script type="text/javascript" src="paging.js"></script>

<?php
	include_once "../classes/hocvien_bs.php";
	include_once "../classes/chuongtrinhhoc_bs.php";
	
	$Keyword = $_GET['key'];
	$Page    = $_GET['pag'];
	
	$HocVien = new hocvien_bs();
	if(trim($Keyword) != "")
		$HocVien->SetHoTen(trim($Keyword));
	$DHocVien = $HocVien->DanhSachHocVienCanThuHocPhi();
	
	$Limit = 20;
	$SoTrang = ceil(count($DHocVien) / $Limit);
	
	$DHocVien = $HocVien->DanhSachHocVienCanThuHocPhiPaging(($Page - 1) * $Limit, $Limit);
?>
<div class="Paging">
	<?php
		if($DHocVien != null)
		{
			if($Page > 1)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",1);'>Đầu</a>";	
			for($i = 1; $i <= $SoTrang; $i++)
			{
				if($Page - 5 <= $i && $i <= $Page + 5)
				{
					if($i == $Page)
						echo "<a class='AjaxPageCur' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>$i</a>";
					else
						echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>$i</a>";
				}
				elseif($i == $Page + 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>...</a>";
				elseif($i == $Page - 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>...</a>";
			}
			if($Page < $SoTrang)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$SoTrang);'>Cuối</a>";	
			
			echo "<span style='float:right; background-color:#4ABDF4; color: #FFF; padding:0px 3px'>Trang $Page/$SoTrang</span>";
		}
	?>
</div>
<div id="KetQuaTimKiem">
	<table id="DataReport">
		<tr>
			<th rowspan="2" class="first">STT</th>
			<th rowspan="2" width="70px">Mã học viên</th>
			<th rowspan="2" colspan="2">Họ tên</th>
			<th rowspan="2">Ngày sinh<br />(d/M/y)</th>
			<th rowspan="2">Điện thoại</th>
			<th rowspan="2" >Ngày<br />đăng ký</th>
			<th colspan="4" class="ColSpan">Học phí</th>
		</tr>
		<tr>
			<th>Học phí <br />(đ)</th>
			<th>Giảm <br />(%)</th>
			<th>Phải nộp <br />(đ)</th>
			<th>Lập <br />hóa đơn</th>
		</tr>
		<!-- Lấy danh sách học viên từ cơ sở dữ liệu -->
		<?php
			if($DHocVien == null)
			{
				echo '<tr><td colspan="11" align="center"> Nội dung rỗng</td></tr>';
			}
			else
			{
				for($i = 0; $i < count($DHocVien); $i++)
				{
					$ChuongTrinhHoc = new chuongtrinhhoc_bs();
					$ChuongTrinhHoc->SetMaChuongTrinh($DHocVien[$i]['MaChuongTrinh']);
					$DChuongTrinhHoc = $ChuongTrinhHoc->LayDanhSach();
					
					$PhaiNop = (1 - $DHocVien[$i]['HocPhiDuocGiam'] / 100) * $DChuongTrinhHoc[0]['HocPhi'];
					
					$HT = TachHoTen($DHocVien[$i]['HoTen']);
					$LinkBill = 'index.php?act=hoadon&id=' . $DHocVien[$i]['MaHocVien'] . '&pin=' . $DHocVien[$i]['PIN'];
					echo '<tr class="ButtonDetails" id="' . $DHocVien[$i]['MaHocVien'] . '">';
						echo '<td align="center"><b>' . (($Page - 1) * $Limit + ($i + 1)) . '</b></td>';
						echo '<td>' . $DHocVien[$i]['MaHocVien'] . '</td>';
						echo '<td>' . $HT[0] . '</td>';
						echo '<td>' . $HT[1] . '</td>';
						echo '<td align="center">' . ConvertDate($DHocVien[$i]['NgaySinh']) . '</td>';
						echo '<td>' . $DHocVien[$i]['DienThoai'] . '</td>';
						echo '<td align="center">' . ConvertDate($DHocVien[$i]['NgayDangKy']) . '</td>';
						echo '<td align="center">' . number_format($DChuongTrinhHoc[0]['HocPhi'], 0, '.', ',') . '</td>';
						echo '<td align="center">' . $DHocVien[$i]['HocPhiDuocGiam'] . '</td>';
						echo '<td align="center">' . number_format($PhaiNop, 0, '.', ',') . '</td>';
						echo '<td align="center"><a href="' . $LinkBill . '"><img src="../data/bill.png" alt="" /></a></td>';
					echo '</tr>';
				}
			}
		?>
	</table>
</div>
<div class="Paging">
	<?php
		if($DHocVien != null)
		{
			if($Page > 1)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",1);'>Đầu</a>";	
			for($i = 1; $i <= $SoTrang; $i++)
			{
				if($Page - 5 <= $i && $i <= $Page + 5)
				{
					if($i == $Page)
						echo "<a class='AjaxPageCur' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>$i</a>";
					else
						echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>$i</a>";
				}
				elseif($i == $Page + 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>...</a>";
				elseif($i == $Page - 6)
					echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$i);'>...</a>";
			}
			if($Page < $SoTrang)
				echo "<a class='AjaxPage' href='#' onclick='javascript:loadXMLDoc2(\"$Keyword\",$SoTrang);'>Cuối</a>";	
			
			echo "<span style='float:right; background-color:#4ABDF4; color: #FFF; padding:0px 3px'>Trang $Page/$SoTrang</span>";
		}
	?>
</div>


